package com.yangyouqi.posthorse.core.service.impl;

import com.yangyouqi.posthorse.core.domain.Customer;
import com.yangyouqi.posthorse.core.domain.Manager;
import com.yangyouqi.posthorse.core.repository.ManagerRepository;
import com.yangyouqi.posthorse.core.service.ManagerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
 * @author 杨友奇
 * @Time 2018/6/7
 */
@Service
public class ManagerServiceImpl implements ManagerService {
    @Autowired
    private ManagerRepository managerRepository;

    @Override
    public Boolean existsusername(String username) {
        return managerRepository.existsByUsername(username);
    }

    @Override
    public Manager register(Manager manager) {
        return managerRepository.save(manager);
    }
    @Override
    public Manager login(String username, String password) {
        return managerRepository.findByUsernameAndPassword(username, password);
    }

    @Override
    public Manager get(Long id) {
        return managerRepository.getOne(id);
    }

    @Override
    public Manager modifyPwd(Long id, String newPwd) {
        Manager manager = managerRepository.getOne(id);
        manager.setPassword(newPwd);
        return managerRepository.save(manager);
    }

    @Override
    public Manager create(Manager manager) {
        return managerRepository.save(manager);
    }
}
